package com.ymatou.mq.api.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.mq.api.parameter.PBBMessage;
import com.ymatou.mq.api.parameter.PublishBatchBean;
import com.ymatou.mq.api.service.PublishBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 发送消息接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_PublishBatch {
	private static PublishBatchBean pb;
	private static PublishBatchCall pc;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发送消息接口");
	}

	@Before
	public void caseUp() {
		pb = new PublishBatchBean();
		pc = new PublishBatchCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(pc.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_PublishBatch_001() {
		Logger.start(true,"批量发送消息接口成功");
		try {
			pb.setAppid("trading");
			pb.setCode("trading_postpay");
			pb.setIp("127.0.0.1");
			List<PBBMessage> items=new ArrayList<PBBMessage>();
			
			PBBMessage item=new PBBMessage();
			String body = TestDataManager.randomStr(20);
			String msgUniqueId=TestDataManager.getRandomUUID().toString();
			item.setMsgUniqueId(msgUniqueId);
			item.setBody(body);
			items.add(item);
			
			PBBMessage item2=new PBBMessage();
			String body2 = TestDataManager.randomStr(20);
			String msgUniqueId2=TestDataManager.getRandomUUID().toString();
			item2.setMsgUniqueId(msgUniqueId2);
			item2.setBody(body2);
			items.add(item2);
			
			pb.setItems(items);
			pc.setData(pb);
			pc.callService();
			Logger.verifyEquals(ECode.SUCCESS, pc.getCode(), "验证Code");
			Logger.verifyEquals(ECode.SUCCESSMSG3, pc.getMsg().toUpperCase(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}